<?php

namespace App\Admin\Controllers;

use App\Models\Tool\Flow;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class FlowController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'Flow';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Flow());

        $grid->column('id', __('ID'));
        $grid->column('uid', __('用户ID'));
        $grid->column('login_ip', __('登录IP'));
        $grid->column('client_type', __('来源'))->using(['magnet' => '磁力集合', 'tool' => '语珞时光机']);
        $grid->column('route_url', __('页面'));
        $grid->column('create_time', __('创建时间'));
        $grid->column('update_time', __('更新时间'));
        $grid->model()->orderByDesc('id');
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Flow::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('uid', __('Uid'));
        $show->field('login_ip', __('Login ip'));
        $show->field('state', __('State'));
        $show->field('client_type', __('Client type'));
        $show->field('route_url', __('Route url'));
        $show->field('is_del', __('Is del'));
        $show->field('create_time', __('Create time'));
        $show->field('update_time', __('Update time'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Flow());

        $form->number('uid', __('Uid'));
        $form->text('login_ip', __('Login ip'));
        $form->switch('state', __('State'));
        $form->text('client_type', __('Client type'));
        $form->text('route_url', __('Route url'));
        $form->switch('is_del', __('Is del'));
        $form->datetime('create_time', __('Create time'))->default(date('Y-m-d H:i:s'));
        $form->datetime('update_time', __('Update time'))->default(date('Y-m-d H:i:s'));

        return $form;
    }
}
